<?php

include_once('logic/action/Action.php');
include_once('logic/view/blog_view.php');

class BlogAction extends Action
{
	public function perform()
	{
		$photos = new PhotosDAO();
		$comments = new CommentsDAO();
		$view = new BlogView();

		$id = HttpRequest::getRequest("id");

		if ($id == "")
		{
			$id = $photos->getLastId();
		}

		$prev = $photos->getPreviousId($id);
		$next = $photos->getNextId($id);

		$view->setParam('_id', $id);
		$view->setParam('_prev', $prev);
		$view->setParam('_next', $next);

		$comments = $comments->getComments($id);
		foreach ($comments as $comment)
		{
				$view->addComment($comment[0],$comment[1],$comment[2]);
		}

		$tmp_title = $photos->getTitle($id);
		$tmp_description = $photos->getDescription($id);
		$tmp_date = $photos->getSubmitDate($id);

		$view->addImageInfo($tmp_title,$tmp_description,$tmp_date);

		$view->display();

	}
}

?>
